// implementation of menu
#include "gs_Menu.h"

gs_Menu::gs_Menu(B_GameStateHandler* handler):B_GameState(handler)
{
    m_env->getSkin()->setFont(m_env->getFont("data/font.bmp"));
    irr::core::dimension2d<irr::s32> d = m_driver->getScreenSize();
    d.Width /= 4; d.Height /= 4;
    m_window = m_env->addStaticText(L"UNONET Game by Darshan M Sonde",
        irr::core::rect<irr::s32>( d.Width,d.Height,d.Width*3,d.Height*3),true );


    m_env->addButton(irr::core::rect<irr::s32>(d.Width-100,70,d.Width+100,120),m_window,101,L"New");
    m_env->addButton(irr::core::rect<irr::s32>(d.Width-100,130,d.Width+100,180),m_window,102,L"Options");
    m_env->addButton(irr::core::rect<irr::s32>(d.Width-100,190,d.Width+100,240),m_window,103,L"Exit");
}

gs_Menu::~gs_Menu()
{
    if(m_window) m_window->remove();
}

void gs_Menu::Render()
{
    m_env->drawAll();
}

void gs_Menu::Update()
{
    m_driver->beginScene(true,true,irr::video::SColor(0,200,200,200));
    Render();
    m_driver->endScene();
}

bool gs_Menu::onEvent(irr::SEvent event)
{
    if( event.EventType == irr::EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown )
    {
		if( event.KeyInput.Key == irr::KEY_ESCAPE )
        {
			m_handler->RequestDestroy();
			return true;
		}
	}

	if( event.EventType == irr::EET_GUI_EVENT )
	{

        if(event.GUIEvent.EventType == irr::gui::EGET_BUTTON_CLICKED )
        {
            irr::s32 id= event.GUIEvent.Caller->getID();
            switch(id)
            {
                case 101: //new
                    m_handler->RequestStateChange("GS_MAIN");
                    return true;
                case 102: //options
                    m_handler->RequestStateChange("ICE_VIDEO_CONFIG");
                    return true;
                case 103: //exit
                    m_handler->RequestDestroy();
                    return true;
            }
        }
    }
    return false;
}
